﻿using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using WebApiV.Data;
using WebApiV.Data.Entity;
using WebApiV.Domain;

namespace WebApiV.Utils
{
    public class DbInitlizer
    {
        public static void Seed(IServiceProvider service)
        {
            using(var score = service.CreateScope())
            {
                var db = score.ServiceProvider.GetService(typeof(Admin2020Db))as Admin2020Db;
                var _user = score.ServiceProvider.GetService(typeof(IRespository<User>))as IRespository<User>;
                var _role = score.ServiceProvider.GetService(typeof(IRespository<Role>)) as IRespository<Role>;
                db.Database.EnsureCreated();

                var emp = db.Users.Any();
                if (!emp)
                {
                    var rloe1 = new Role
                    {
                        RoleName = "奥特曼",
                        ShortTell = "打怪兽",
                    };
                    _role.Insert(rloe1);

                    _user.InsertBlck(new User[]
                    {
                    new User
                    {
                        userName="泰罗",
                        PassWord="123456",
                        RoleId=rloe1.Id,
                    },
                    new User
                    {
                        userName="塞罗",
                        PassWord="654321",
                        RoleId=rloe1.Id,
                    }
                    });
                }               
            }
        }
    }
}
